Skip to content

fix: correct newline handling for p and x commands#378

Merged
sylvestre merged 1 commit intouutils:mainfrom
pocopepe:issue-306-143
Apr 23, 2026
Merged

fix: correct newline handling for p and x commands#378
sylvestre merged 1 commit intouutils:mainfrom
pocopepe:issue-306-143

Conversation

@pocopepe
Copy link
Copy Markdown
Contributor

Fixes #306 and #143

  • Hold space was initialized without has_newline: true, causing 1x to output nothing instead of an empty line when input has no trailing newline
  • p was unconditionally appending \n, breaking -n p on no-newline input

Fixed by initializing hold space as newline terminated and adding a pending_newline mechanism in OutputBuffer that defers newline injection until the next write, so -n mode never triggers it
Also incidentally fixes the g/G empty hold space behavior from #266 (overlaps with open PR #263 same bug, different approach)

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

❌ Patch coverage is 78.57143% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.25%. Comparing base (7b204c0) to head (456e9db).
⚠️ Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
src/sed/fast_io.rs 79.34% 18 Missing and 1 partial ⚠️
src/sed/processor.rs 0.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #378      +/-   ##
==========================================
- Coverage   82.25%   82.25%   -0.01%     
==========================================
  Files          13       13              
  Lines        5438     5522      +84     
  Branches      304      310       +6     
==========================================
+ Hits         4473     4542      +69     
- Misses        963      977      +14     
- Partials        2        3       +1     
Flag Coverage Δ
macos_latest 82.94% <93.90%> (+0.23%) ⬆️
ubuntu_latest 83.04% <93.90%> (+0.23%) ⬆️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 5.12%

⚡ 1 improved benchmark
❌ 3 regressed benchmarks
✅ 7 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
access_log_append 639.7 ms 669.7 ms -4.48%
no_op_short 977.8 ms 1,030.6 ms -5.12%
access_log_all_del 543.7 ms 523.7 ms +3.82%
access_log_no_op 754.7 ms 781.1 ms -3.38%

Comparing pocopepe:issue-306-143 (456e9db) with main (0cf23a8)

Open in CodSpeed

Copy link
Copy Markdown
Collaborator

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please squash the commits into a single one.

@pocopepe
Copy link
Copy Markdown
Contributor Author

squashed into one commit :)

@sylvestre sylvestre merged commit d7a713e into uutils:main Apr 23, 2026
27 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1x should output empty line if input doesn't contain newline

3 participants